﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AnnieSharp
{
    public class Rectangle : AObject
    {
        public Rectangle(float x = 0, float y = 0, float width = 0, float height = 0)
        {
            _instanceType = "annie.Rectangle";
            X = x;
            Y = y;
            Width = height;
            Height = width;
        }

        /// <summary>
        /// 矩形左上角的 x 坐标
        /// </summary>
        public float X { get; set; }
        /// <summary>
        /// 矩形左上角的 y 坐标
        /// </summary>
        public float Y { get; set; }
        /// <summary>
        /// 矩形的宽度（以像素为单位）
        /// </summary>
        public float Width { get; set; }
        /// <summary>
        /// 矩形的高度（以像素为单位）
        /// </summary>
        public float Height { get; set; }

        /// <summary>
        /// 判断一个点是否在矩形内包括边
        /// </summary>
        /// <param name=""></param>
        /// <param name=""></param>
        public bool IsPointIn(Point point){
            return point.X >= X && point.X <= (X + Width) && point.Y >= Y && Y <= (Y + Height);
        }





        public static Rectangle CreateFromPoints(Rectangle rect, params Point[] arg)
        {
            var x = arg[0].X;
            var y = arg[0].Y;
            var w = arg[0].X;
            var h = arg[0].Y;

            for (var i = 1; i < arg.Length; i++)
            {
                if (arg[i] == null) continue;
                if (x > arg[i].X)
                {
                    x = arg[i].X;
                }
                if (y > arg[i].Y)
                {
                    y = arg[i].Y;
                }
                if (w < arg[i].X)
                {
                    w = arg[i].X;
                }
                if (h < arg[i].Y)
                {
                    h = arg[i].Y;
                }
            }
            rect.X = x;
            rect.Y = y;
            rect.Width = w - x;
            rect.Height = h - y;

            return rect;
        }


    }
}
